package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Processmaster;
import com.restaurant.service.ProcessmasterService;

public class ProcessmasterServiceImpl implements ProcessmasterService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Processmaster addOrModify( Processmaster objProcessmaster ) {
       return ( Processmaster ) hibernateTemplate.merge( objProcessmaster );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Processmaster deleteRecord( Processmaster objProcessmaster ) {
       hibernateTemplate.delete( objProcessmaster );
       return objProcessmaster;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Processmaster modifyRecord( Processmaster objProcessmaster ) {
       return ( Processmaster ) hibernateTemplate.merge( objProcessmaster );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Processmaster> loadAll() {
       return (List<Processmaster>)hibernateTemplate.findByNamedQuery( "Processmaster.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Processmaster loadByPrimaryKey( Long primaryKey ) {
       return (Processmaster) hibernateTemplate.get( Processmaster.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Processmaster deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Processmaster> loadByHql(String query) {
       return ( List<Processmaster> ) hibernateTemplate.find( query );
   }
}